package se.webbzon.oschi01.worldcamera;

public class Rectangle implements Area {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1396964675026210900L;
	
	// The position and size of this rectangle
	protected double x, y, w, h;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new rectangle at (0,0) with the size width = 1, height = 1. **/
	public Rectangle() {
		this(0,0,1,1);
	}
	
	public Rectangle(double x, double y, double w, double h) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the x-position of this rectangle. **/
	public double getX() {
		return x;
	}
	
	/** Returns the y-position of this rectangle. **/
	public double getY() {
		return y;
	}
	
	/** Returns the width of this rectangle. **/
	public double getWidth() {
		return w;
	}
	
	/** Returns the height of this rectangle. **/
	public double getHeight() {
		return h;
	}
	
	/** Sets the position and size of this rectangle. **/
	public void set(double x, double y, double w, double h) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}
	
	/** Sets the position and size of this rectangle. **/
	public void set(Rectangle rectangle) {
		this.x = rectangle.getX();
		this.y = rectangle.getY();
		this.w = rectangle.getWidth();
		this.h = rectangle.getHeight();
	}

	@Override public boolean contains(double x, double y) {
		return x >= this.x && x < this.x + w && y >= this.y && y < this.y + h;
	}

	@Override public void getBoundary(Rectangle boundary) {
		boundary.set(x, y, w, h);
	}
	
	@Override public Rectangle clone() {
		return new Rectangle(x,y,w,h);
	}

}
